home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 108 / MacAddict108.iso / Software / Internet & Communication / JunkMatcher 1.5.5.dmg / JunkMatcher.app / Contents / Resources / PythonGlue.py < prev    next >
Encoding:
Python Source  |  2005-06-01  |  1.6 KB  |  41 lines

  1. # Skeleton Python source for embedding Python into ObjC programs.
  2. # This source file expects to be run by the ObjC code in PythonGlue.m
  3. # and it expects to live in Contents/Resources of some .app bundle.
  4. # It will add the Resources folder and its PyObjC subfolder to
  5. # sys.path and import any modules found in Resources (which in
  6. # turn makes any PyObjC classes in these modules available to the
  7. # ObjC runtime system).
  8. import os
  9. import sys
  10.  
  11. DEBUG = 0
  12.  
  13. def main():
  14.     # First find the Resource folder of the current application
  15.     resource_folder, ourname = os.path.split(__file__)
  16.     if DEBUG:
  17.         print "PythonGlue: resource folder:", resource_folder
  18.     
  19.     # IMPORTANT: 1. Make our Engine folder the first one; 2. Make the path to our own PyObjC
  20.     #               installation appear *before* the system-wide PyObjC, if exists.
  21.     sys.path.insert(0, resource_folder)
  22.     sys.path.insert(0, os.path.join(resource_folder, "lib/python2.3/site-packages/PyObjC"))
  23.     sys.path.insert(0, os.path.join(resource_folder, "Engine"))
  24.     
  25.     # Now import all modules from the resource folder
  26.     count = 0
  27.     extension = '.py'
  28.     extensionLen = len(extension)
  29.     for filename in os.listdir(resource_folder):
  30.         if filename[-extensionLen:] == extension and filename != ourname:
  31.             module_name = filename[:-extensionLen]
  32.             if DEBUG:
  33.                 print "PythonGlue: import", module_name
  34.             __import__(filename[:-extensionLen])
  35.             count = count + 1
  36.     if count == 0:
  37.         print "PythonGlue: Warning: no Python modules found"
  38.             
  39. if __name__ == '__main__':
  40.     main()
  41.